<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="../../../src/base/_core.js"></script>
    <script type="text/javascript" src="../../../src/core/env.js"></script>
</head>
<body>
<div id="div1" style="width:200px; height:200px; border: 1px solid #f00; background: #eee;"></div>
<div id="div2" style="width:300px; height:200px; border: 1px solid #0f0; background: #ccc;"></div>

<table id="tb1">
    <tr>
        <td><a href="#">baidu</a></td>
        <td><a href="#">sina</a></td>
        <td><a href="#">网易</a></td>
    </tr>
    <tr>
        <td><a href="#">baidu</a></td>
        <td><a href="#">sina</a></td>
        <td><a href="#">网易</a></td>
    </tr>
</table>

<script type="text/javascript">
    /**
     * Jquery事件对象作了cache:

     if (event[ jQuery.expando ]) {
     return event;
     }

     */
    (function (line, browser, document, window) {
        var rKeys=/key/g;
        var rMouse=/(?:mouse)|click/g;
        var rTouch=/touch/g;

        //fruit.event.Event
        //'click dbclick input'.split(' ');

        //fruit.event.MouseEvent
        //'mouseover mouseout mouseenter mouseleave ...'.splite(' ');

        //fruit.event.KeyBoardEvent
        //'keypress keydown keyup ...'.split(' ');

        //w3c attrs: pageX,pageY,offsetX,offsetY.... is the default.
        //In ie browser, fixed attrs will override the default event{}.

        define('fruit.Event', null, {
            init:function (original) {
                this.originalEvent = original;
                this.type = original.type;
                this.timeStamp = original.timeStamp || Date.now();
            },
            getPageX:function(){

            },
            //TODO:method:preventDefault/stopPropagation/ must be in the fruit.Event's prototype.
            normalize:function (event,original) {
                if(!original.preventDefault){
                    event.preventDefault=function(){};
                }
                if(!original.stopPropagation){
                    event.stopPropagation=function(){};
                }

                //TODO:This maybe more simple.
                if(rKeys.test(this.type)){
                    return new fruit.Event.fixKey(event,original);
                }else if(rMouse.test(this.type)){
                    return new fruit.Event.fixMouse(event,original);
                }else{

                }
            }
        });
        define('fruit.Event.fixKey', null, {
            init:function(event,original){
                if(original.which && !original.button){
                    event.which='xxx';
                }
                //...
                return event;
            }
        });
        define('fruit.Event.fixMouse', null, {
            init:function(event,original){
                if(!original.pageX){
                    event.pageX='xxx';
                }
                //...
                return event;
            }
        });
    }(line, line.browser, document, window));
    var div1 = document.getElementById('div1');
    var div2 = document.getElementById('div2');
    var tb1 = document.getElementById('tb1');
    div1.onclick = function (ev) {
        console.log('mouse click :', ev);
    };
    div2.onmouseover = function (ev) {
        console.log('mouse over :', ev);
    };
    tb1.onmouseover = function (ev) {
        console.log('tb1 mouse over :', ev);
    };
</script>
</body>
</html>